﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Lyon.Utility
{
    /// <summary>
    /// 友好显示
    /// </summary>
    static public class DisplayUtility
    {
        /// <summary>
        /// 文件大小
        /// </summary>
        /// <param name="fileSize"></param>
        /// <returns></returns>
        static public string ToFileSize(long fileSize)
        {
            int decimals = 2;
            decimal number;
            if (fileSize <= 0x400L)
            {
                return (fileSize.ToString() + " 字节");
            }
            if (fileSize <= 0x100000L)
            {
                number = fileSize / 1024M;
                return (Math.Round(number, decimals).ToString() + " KB");
            }
            if (fileSize <= 0x40000000L)
            {
                number = fileSize / 1048576M;
                return (Math.Round(number, decimals).ToString() + " MB");
            }
            if (fileSize <= 0x10000000000L)
            {
                number = fileSize / 1073741824M;
                return (Math.Round(number, decimals).ToString() + " GB");
            }
            if (fileSize <= 0x4000000000000L)
            {
                number = fileSize / 1099511627776M;
                return (Math.Round(number, decimals).ToString() + " TB");
            }
            return "大于1TB";
        }
        /// <summary>
        /// 时间间隔
        /// </summary>
        /// <param name="ts"></param>
        /// <returns></returns>
        static public string ToTimeSpan(TimeSpan ts)
        {
            int decimals = 2;
            if (ts.TotalDays > 1)
                return (Math.Round(ts.TotalDays, decimals).ToString() + " 天");
            if (ts.TotalHours > 1)
                return (Math.Round(ts.TotalHours, decimals).ToString() + " 时");
            if (ts.TotalMinutes > 1)
                return (Math.Round(ts.TotalMinutes, decimals).ToString() + " 分");
            if (ts.TotalSeconds > 1)
                return (Math.Round(ts.TotalSeconds, decimals).ToString() + " 秒");
            if (ts.TotalMilliseconds > 1)
                return (Math.Round(ts.TotalMilliseconds, decimals).ToString() + " 毫秒");
            return "小于1毫秒";
        }
        /// <summary>
        /// 系统名称
        /// </summary>
        /// <param name="oSVersion"></param>
        /// <returns></returns>
        static public string ToSystemName(OperatingSystem oSVersion)
        {
            string str = "Unknown";
            switch (oSVersion.Platform)
            {
                case PlatformID.Win32Windows:
                    switch (oSVersion.Version.Minor)
                    {
                        case 0:
                            return "Windows 95";

                        case 10:
                            return "Windows 98";

                        case 90:
                            return "Windows ME";
                    }
                    return str;

                case PlatformID.Win32NT:
                    switch (oSVersion.Version.Major)
                    {
                        case 3:
                            return "Windws NT 3.51";

                        case 4:
                            return "Windows NT 4";

                        case 5:
                            switch (oSVersion.Version.Minor)
                            {
                                case 0:
                                    return "Windows 2000";

                                case 1:
                                    return "Windows XP";

                                case 2:
                                    return "Windows Server 2003";
                            }
                            return str;

                        case 6:
                            switch (oSVersion.Version.Minor)
                            {
                                case 0:
                                    return "Windows Vista";

                                case 1:
                                    return "Windows 7";
                            }
                            return str;
                    }
                    return str;
            }
            return str;
        }
    }
}
